#include "FServer/MySQL/MySQLTCPHandler.h"

#include "FServer/MySQL/MySQLParser.h"
#include "FServer/MySQL/MySQLStatement.h"

namespace keeper_server {

void MySQLTCPHandler::handleRequest(MySQLPacket& handle_packet) {
  MySQLCommand cmdType = getRequestCommandType(handle_packet);

  switch (cmdType) {
    case MYSQL_COM_QUERY: {
      handleQueryCommand(handle_packet);
    } break;
    default:
      break;
      //  MYSQL_COM_QUIT,
      //  MYSQL_COM_INIT_DB,
      //  MYSQL_COM_QUERY,
      //  MYSQL_COM_FIELD_LIST,
      //  MYSQL_COM_CREATE_DB,
      //  MYSQL_COM_DROP_DB,
      //  MYSQL_COM_REFRESH,
      //  MYSQL_COM_SHUTDOWN,
      //  MYSQL_COM_STATISTICS,
      //  MYSQL_COM_PROCESS_INFO,
      //  MYSQL_COM_CONNECT,
      //  MYSQL_COM_PROCESS_KILL,
      //  MYSQL_COM_DEBUG,
      //  MYSQL_COM_PING,
      //  MYSQL_COM_TIME,
      //  MYSQL_COM_DELAYED_INSERT,
      //  MYSQL_COM_CHANGE_USER,
      //  MYSQL_COM_BINLOG_DUMP,
      //  MYSQL_COM_TABLE_DUMP,
      //  MYSQL_COM_CONNECT_OUT,
      //  MYSQL_COM_REGISTER_SLAVE,
      //  MYSQL_COM_PREPARE,
      //  MYSQL_COM_EXECUTE,
      //  MYSQL_COM_LONG_DATA,
      //  MYSQL_COM_CLOSE_STMT,
      //  MYSQL_COM_RESET_STMT,
      //  MYSQL_COM_SET_OPTION,
      //  MYSQL_COM_FETCH_STMT,
      //  MYSQL_COM_DAEMON,
      //  MYSQL_COM_BINLOG_DUMP_GTID,
  }
}
void MySQLTCPHandler::handleQueryCommand(MySQLPacket& handle_packet) {
  auto query_command = getCommandSQL(handle_packet);
  LOG_INFO("get query command:%s", query_command);
  String cmd_str = query_command;
  MySQLStatement stmt;
  MySQLParser parser(stmt);

  parser.parse(cmd_str);
  stmt.print_info();
}

}  // namespace keeper_server
